#include "precompiled.h"
#include "prs_FrmBuildData.h"
using namespace prs;

// TFrmBuildData //////////////////////////////////////////////////////////////

//
void TFrmBuildData::Visit(TNodeFrmString &Node)
{ 
/*******
  TFrmBuildData V(Level+1); 
  V.SInfo << V.sOffs << "string=\"" << Node.Value.GetValue() << "\"";
  
  Node.AcceptChildren(V);
  SInfo << "\r\n" << V.SInfo;
***********/

  Node.AcceptChildren(*this);
}

//
void TFrmBuildData::Visit(TNodeFrmTableGrid &Node)
{ 
  TFrmBuildData V(Level+1); 
  V.SInfo << V.sOffs << "tableGrid";
  
  Node.AcceptChildren(V);
  SInfo << "\r\n" << V.SInfo;
}

//
void TFrmBuildData::Visit(TNodeFrmRowCaption &Node)
{ 
  TFrmBuildData V(Level+1); 
  V.SInfo << V.sOffs << "rowCaption";
  
  Node.AcceptChildren(V);
  SInfo << "\r\n" << V.SInfo;
}

//
void TFrmBuildData::Visit(TNodeFrmRowChildren &Node)
{ 
  if (Node.GetChildrenCount() > 0) {
    TFrmBuildData V(Level+1); 
    V.SInfo << V.sOffs << "rowChildren";
    
    Node.AcceptChildren(V);
    SInfo << "\r\n" << V.SInfo;
  }
  else {
    Node.AcceptChildren(*this);
  }
}

//
void TFrmBuildData::Visit(TNodeFrmCol &Node)
{ 

  TFrmBuildData V(Level+1); 

  V.SInfo << V.sOffs << "col";

  Node.AcceptChildren(V);
  SInfo << "\r\n" << V.SInfo;


  //Node.AcceptChildren(*this);
}

//
void TFrmBuildData::Visit(TNodeUseTemplate &Node)
{
/********
  ////////////////////////////////////////////
  svl::TMessageModalEx(svl_GetClassName(*this)
    << "\r\nParams:\r\n" << Node.Params.Array.GetInfoAsString()
  );
*********/

  bool IsDm = false;
  TFrmBuildData V(Level+1); 
  V.SInfo << V.sOffs << "UseTemplate: " << Node.NodeDefTemplateId.GetValue() << "(";

  for (int Nparam = 0; Nparam < Node.Params.Array.Count(); Nparam++) {
    TNodeUseTemplateParam &Param = Node.Params.Array.Get(Nparam);

    TFrmValue *Value = dynamic_cast<TFrmValue*>(
      Param.DefValue.GetValue()
    );
    if (Value) {
      svl::TString STable = Value->Table;
      svl::TString SField = Value->Field;

      svl::TString SValue;

      if (STable.Len() && SField.Len()) {
        TFrmStringValue *StringValue = dynamic_cast<TFrmStringValue*>(Value);
        if (StringValue) {
          SValue << "\"" << StringValue->Value.GetValue() << "\" ";
        }
      
        V.SInfo << Param.Id.GetValue() << "=";
        V.SInfo << SValue;
        IsDm = true;
      }
    }


/**********
    svl::TVariant Value;
    TNodeFrmLinkAttr::GetAttrValueInParent(&Param,Value);
    
    V.SInfo << " " << Param.Id.GetValue() << "="; 
    
    if (Value.GetEType() == svl::TVariant::EType_String) {
      V.SInfo << "\"" << Value.String() << "\"";
      IsOk = true;
    }
************/    
  }
  V.SInfo << ")";

  if (IsDm) {
    Node.AcceptChildren(V);
    SInfo << "\r\n" << V.SInfo;
  }
  else {
    Node.AcceptChildren(*this);
  }
}
